//
//  FamilyDescVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/29.
//  Copyright © 2020 tym. All rights reserved.
//

#import "FamilyDescVC.h"
#import "Colors.h"
#import "UserModel.h"
#import "FamilyModel.h"
#import "Sizes.h"
#import "FamilyService.h"
#import "UIimage+Extends.h"
#import "WHToast.h"
#import "UIButton+Gradient.h"
#import "UIView+ZFFrame.h"

@interface FamilyDescVC ()

@property(nonatomic,weak) IBOutlet  UITextField  *descFid;
@property(nonatomic,weak) IBOutlet UIButton  *goBtn;

@property(nonatomic,strong) FamilyService *service;
@end

@implementation FamilyDescVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"家庭描述"];
    self.goBtn.layer.cornerRadius = 5;
    self.goBtn.layer.masksToBounds = YES;
    self.goBtn.zf_width = ScreenWidth - 60;
    self.descFid.text = [UserTool getCurrentFamily].familyDesc;
    
    [self.descFid addTarget:self action:@selector(changedTextField:) forControlEvents:UIControlEventEditingChanged];
    [self changedTextField:nil];
}

-(void)changedTextField:(UITextField*)fid{
    if (self.descFid.text.length<1) {
        [self.goBtn setBackgroundImage:[UIImage imageWithColor:rgba(230, 230, 230) withSize:self.goBtn.bounds.size] forState:UIControlStateNormal];
    }else{
        [self.goBtn gradientButtonWithSize:CGSizeMake(300, 44) colorArray:@[(id)rgba(139, 175, 255),(id)rgba(76, 132, 255)] percentageArray:@[@(0.5),@(1)] gradientType:GradientFromLeftTopToRightBottom];
    }
}

-(FamilyService*)service{
    if (_service == nil) {
        _service = [[FamilyService alloc] init];
    }
    return _service;
}

-(IBAction)changeFamilyNameAction:(id)sender{
    
    [self.service getUpdateFamilyWithFamilyId:self.familymodel.familyId FamilyName:self.familymodel.familyName  desc:self.descFid.text image:@"" completion:^(LMJBaseResponse *response) {
        if (response.message) {
            [WHToast showMessage:response.message duration:2 finishHandler:nil];
        }else{
            [WHToast showMessage:@"修改成功" duration:2 finishHandler:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
    }];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
